from models import db

good_user = db.Table(
    "good_user",
    db.Column('user_id',db.Integer,db.ForeignKey('user.id'),nullable=False, primary_key=True),
    db.Column('good_id',db.Integer,db.ForeignKey('good.id'),nullable=False, primary_key=True)
)


class Good(db.Model):
    __tablename__ = "good"
    id = db.Column(db.Integer,primary_key=True)
    price = db.Column('price',db.Float)
    title = db.Column('title',db.String(64))
    descreption = db.Column('descreption',db.String(128))
    users = db.relationship("User", backref="good", secondary=good_user)
    orderdetails = db.relationship('OrderDetail',backref='good',lazy='dynamic')

    def __repr__(self):
        return self.id
